﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;
using Ninject;
using Ninject.Parameters;
using Ninject.Syntax;
using SampleTryouts.Models;

namespace SampleTryouts.Infrastructure
{
    // Moving the complete implementation of the Ninject from the HomeController::CalculateProductTotal()

    public class NinjectDependencyResolver : /* Added by Mega */ IDependencyResolver
    {
        private IKernel kernel;

        public NinjectDependencyResolver()
        {
            kernel = new StandardKernel();
            AddBindings();
        }

        private void AddBindings()
        {
            kernel.Bind<IValueCalculator>().To<LinqValueCalculator>();
            kernel.Bind<IDiscountHelper>().To<MinimumDiscountHelper>().WhenInjectedInto<LinqValueCalculator>();
            // not sure how to pass both the constructor args and the myProducts list using Ninject hence left it here...
            //kernel.Bind<IShoppingCart>().To<ShoppingCart>().WithPropertyValue("Products", ????????
            //kernel.Bind<IShoppingCart>().ToConstructor<ShoppingCart>(ctorArg => new ShoppingCart(ctorArg.Inject<IValueCalculator>()));            

        }

        public object GetService(Type serviceType)
        {
            return kernel.TryGet(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return kernel.GetAll(serviceType);
        }
    }
}